<?php

namespace app\model;

abstract class BaseModel {

    protected $CORE;
    protected $con;

    public function __construct() {
        $this->CORE = getInstance();
    }

    protected function getDBname() {
        if (!isset($this->dbname)) {
            throw new \Exception('库名不存在');
        }
        return $this->dbname;
    }

    protected function getTableName() {
        if (!isset($this->tablename)) {
            throw new \Exception('库名不存在');
        }
        return $this->tablename;
    }

    protected function _insert(array $insertData) {
        try {
            $con = $this->CORE->db->_instance($this->getDBname());
            $insertId = $con->_insert($this->getTableName(), $insertData);
            return $insertId > 0 ? outputObject(TRUE, '成功写入数据', $insertId) : outputObject(FALSE, '写入数据失败');
        } catch (\Exception $e) {
            return outputObject(FALSE, '数据库写入数据发生异常：' . $e->getMessage());
        }
    }
}
